//最大连续1的个数 III
//测试链接 https://leetcode.cn/problems/max-consecutive-ones-iii/description/
public class LongestOnes {
    public int longestOnes(int[] nums, int k) {
        int left = 0, right = 0, n = nums.length;
        int zero = 0;
        int len = 0;
        while(right < n){
            if(nums[right] == 0){  //进窗口
                zero++; //0的个数
            }
            while(zero > k){  //出窗口
                if(nums[left++] == 0)
                    zero--;
            }
            //判断结束，此时zero的数量小于等于k
            len = Math.max(len, right - left + 1);
            right++;
        }
        return len;
    }
}
